package com.wf.course.web.controller.comm;


import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.utils.page.PageBean;
import com.wf.course.model.comm.ActivityEntry;
import com.wf.course.service.IActivityEntryService;
import com.wf.course.web.Interceptor.LogInfo;

/**
 *活动参与人信息管理
 */
@RequestMapping("activityEntry")
@Controller
public class ActivityEntryController {

	@Autowired
	private IActivityEntryService activityEntryService;

	
	 /***
	  * 管理
	  * @param pageNo
	  * @param pageSize
	  * @param title
	  * @param model
	  * @return
	  */
	@LogInfo("查询活动参与人信息列表查询")
	@RequestMapping("activityEntryList")
	public String activityEntryList(@RequestParam(value = "pageNo", required = false) Integer pageNo,
						  @RequestParam(value = "pageSize", required = false) Integer pageSize,
						  @RequestParam(value = "program", required = false) String program,
						  @RequestParam(value = "participants", required = false) String participants,
						  @RequestParam(value = "activityId", required = false) String activityId,
						  @RequestParam(value = "registrationTimeBegin", required = false) String registrationTimeBegin,
						  @RequestParam(value = "registrationTimeEnd", required = false) String registrationTimeEnd,
 						  Model model){
		Map<String,Object> map=new HashMap<String,Object>(); 
		if(program!=null && !"".equals(program)){
			map.put("program",program);
		}
		if(participants!=null && !"".equals(participants)){
			map.put("participants",participants);
		}
		if(activityId!=null && !"".equals(activityId)){
			map.put("activityId",activityId);
		}
		if(registrationTimeBegin!=null && !"".equals(registrationTimeBegin)){
			map.put("registrationTimeBegin",registrationTimeBegin);
		}
		if(registrationTimeEnd!=null && !"".equals(registrationTimeEnd)){
			map.put("registrationTimeEnd",registrationTimeEnd);
		}
		
		PageBean<ActivityEntry> pageBean = new PageBean<ActivityEntry>(pageNo, pageSize,null,map);
		
		activityEntryService.getActivityEntryList(pageBean);
		pageBean.setUrl("/activityEntry/activityEntryList");
		model.addAttribute("page", pageBean);
		
		return "comm/activityEntryList";
	}
	
	/**
	 * 新增修改页面信息加载
	 * @param id
	 * @return
	 */
	@LogInfo("新增/修改活动参与人信息，页面数据初始化")
	@RequestMapping("downLoadActivityEntry/{id}")
	public String downLoadActivityEntry(@PathVariable("id") Integer id,Model model){
		 if(id!=null && id!=0){
			 ActivityEntry activityEntry = this.activityEntryService.downLoadActivityEntry(id);
				model.addAttribute("activityEntry", activityEntry);
				model.addAttribute("type", "upd");
		 }else{
			 model.addAttribute("type", "add");
		 }
		 
		return "comm/areaEdit";		
	}
	
	
	/**
	 * 添加或修改
	 * @param activityEntry
	 * @param request
	 * @return
	 */
	@LogInfo("添加或修改活动参与人信息")
	@RequestMapping(value = {"activityEntryEdit" } )
	public String activityEntryEdit(@ModelAttribute ActivityEntry activityEntry, 
 			HttpServletRequest request){
		 
			//添加信息
			if(activityEntry.getId()==null){				 
				//保存
				activityEntryService.saveActivityEntry(activityEntry);
			}else{
				//修改			
				activityEntryService.updateActivityEntry(activityEntry);				
			}		 
		 
		return "redirect:/activityEntry/activityEntryList";
		
	}
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@LogInfo("删除活动参与人信息")
	@RequestMapping(value="deleteActivityEntry/{id}"  )
	public String deleteActivityEntry(@PathVariable Integer id){
			this.activityEntryService.deleteActivityEntry(id);
			
			return "redirect:/activityEntry/activityEntryList";
	}
	
}
